package 设计模式.proxy.cglib_proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class ProxyFactory implements MethodInterceptor{

    private Station station = new Station();

    public Station getProxy(){
        //创建Enhancer对象，类似于JDK代理中的Proxy类
        Enhancer enhancer = new Enhancer();
        //设置父类的字节码对象。指定父类
        enhancer.setSuperclass(Station.class);
        //设置回调函数
        enhancer.setCallback(this);
        //创建代理对象
        Station proxyObject = (Station) enhancer.create();

        return proxyObject;
    }


    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("代理收取服务费");
//        Object object = method.invoke(station, objects);
        return null;
    }
}
